package timeslice
{
	import display.ImageSlot;
	
	import flash.display.DisplayObject;
	import flash.geom.ColorTransform;
	
	import global.$R;
	import global.$talkScene;
	
	import slices.FadeInDisplayObject;
	import slices.TimeSlice;
	import globals.$athena;
	
	import resources.RTProfile;
	import slices.InvokeFunction;
	
	public class TalkSceneAddChar extends TimeSlice
	{
		public var id:Object; 
		public var pos:int;
		public var max:int;
		public var emotion:int;
		public var back:Boolean;
		
		public function TalkSceneAddChar(id:Object, pos:int, emotion:int=0, back:Boolean=true, max:int=4)
		{
			super();
			this.id = id;
			this.pos = pos;
			this.max = max;
			this.emotion = emotion;
			this.back = back;
		}
		
		override public function onStart():void {
			var pf:DisplayObject = $R.getProfile(id, emotion);
			var slot:ImageSlot = new ImageSlot();
			pf.x = -pf.width/2;
			slot.setContent(pf);
			RTProfile.layTo(slot, pos, max);
			if (back) {
				var cm:ColorTransform = new ColorTransform(0.4, 0.4, 0.4);
				slot.transform.colorTransform = cm;
			} else {
				$talkScene.fontID = id;
			}
			$talkScene.addChar(id, emotion, slot);
			slot.alpha = 0;
			var fade:FadeInDisplayObject = new FadeInDisplayObject(slot, 0.1);
			fade.appendNext(new InvokeFunction(onFadeIn));
			$athena.addTimeSlice(fade);
		}
		
		private function onFadeIn():void {
			isEnd = true;
		}
	}
}